package com.shop2cn.iapi.subscription.testcase;

import org.junit.After;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.subscription.parameter.*;
import com.shop2cn.iapi.subscription.service.*;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodmchSubscriptionService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*查询商家收费功能是否可用Test
*FreeMaker Template自动生成代码
*/

@TestSuite
public class Ts_GetSubscriptionStatus{
	private static GetSubscriptionStatusBean getsubscriptionstatusBean;
	private static GetSubscriptionStatusCall getsubscriptionstatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询商家收费功能是否可用Test");
	}

	@Before
	public void caseUp() {
		getsubscriptionstatusBean=new GetSubscriptionStatusBean();
		getsubscriptionstatusCall=new GetSubscriptionStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsubscriptionstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionStatus_001() {
		Logger.start(true,"直播付费一年，是否可用，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//创建付费订单
			GodmchSubscriptionService.ApplyCharge(mchId,0,3);
			//付费订单回调通知
			GodmchSubscriptionService.ChargeNotify(mchId);
			
			getsubscriptionstatusBean.setMchId(mchId);
			getsubscriptionstatusBean.setFuncType(0);
			getsubscriptionstatusCall.setData(getsubscriptionstatusBean);
			getsubscriptionstatusCall.callService();			
			Logger.verifyEquals("200", getsubscriptionstatusCall.getString("code"), "验证code");
			JsonObject data = getsubscriptionstatusCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals(true, data.get("available").getAsBoolean(), "验证available");
			Logger.verifyEquals(364, data.get("availableDay").getAsInt(), "验证availableDay");
			Logger.verifyEquals(3, data.get("subscriptionStatus").getAsInt(), "验证subscriptionStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionStatus_002() {
		Logger.start(true,"直播试用一月，是否可用，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//申请试用一月
			GodmchSubscriptionService.applyTryout(mchId,0,1);
			
			getsubscriptionstatusBean.setMchId(mchId);
			getsubscriptionstatusBean.setFuncType(0);
			getsubscriptionstatusCall.setData(getsubscriptionstatusBean);
			getsubscriptionstatusCall.callService();			
			Logger.verifyEquals("200", getsubscriptionstatusCall.getString("code"), "验证code");
			JsonObject data = getsubscriptionstatusCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals(true, data.get("available").getAsBoolean(), "验证available");
			Logger.verifyEquals(29, data.get("availableDay").getAsInt(), "验证availableDay");
			Logger.verifyEquals(1, data.get("subscriptionStatus").getAsInt(), "验证subscriptionStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionStatus_003() {
		Logger.start(true,"直播试用一月+订购一年，是否可用，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//申请试用一月
			GodmchSubscriptionService.applyTryout(mchId,0,1);
			Thread.sleep(1000);
			//创建付费订单
			GodmchSubscriptionService.ApplyCharge(mchId,0,3);
			//付费订单回调通知
			GodmchSubscriptionService.ChargeNotify(mchId);
			
			getsubscriptionstatusBean.setMchId(mchId);
			getsubscriptionstatusBean.setFuncType(0);
			getsubscriptionstatusCall.setData(getsubscriptionstatusBean);
			getsubscriptionstatusCall.callService();			
			Logger.verifyEquals("200", getsubscriptionstatusCall.getString("code"), "验证code");
			JsonObject data = getsubscriptionstatusCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals(true, data.get("available").getAsBoolean(), "验证available");
			Logger.verifyEquals(394, data.get("availableDay").getAsInt(), "验证availableDay");
			Logger.verifyEquals(3, data.get("subscriptionStatus").getAsInt(), "验证subscriptionStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionStatus_004() {
		Logger.start(true,"直播订购一年，再试用一月，是否可用，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//创建付费订单
			GodmchSubscriptionService.ApplyCharge(mchId,0,3);
			//付费订单回调通知
			GodmchSubscriptionService.ChargeNotify(mchId);
			Thread.sleep(1000);
			//申请试用一月
			GodmchSubscriptionService.applyTryout(mchId,0,1);
			
			getsubscriptionstatusBean.setMchId(mchId);
			getsubscriptionstatusBean.setFuncType(0);
			getsubscriptionstatusCall.setData(getsubscriptionstatusBean);
			getsubscriptionstatusCall.callService();			
			Logger.verifyEquals("200", getsubscriptionstatusCall.getString("code"), "验证code");
			JsonObject data = getsubscriptionstatusCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals(true, data.get("available").getAsBoolean(), "验证available");
			Logger.verifyEquals(394, data.get("availableDay").getAsInt(), "验证availableDay");
			Logger.verifyEquals(1, data.get("subscriptionStatus").getAsInt(), "验证subscriptionStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionStatus_005() {
		Logger.start(true,"商户未订购或者试用，测试是否可用，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			
			getsubscriptionstatusBean.setMchId(mchId);
			getsubscriptionstatusBean.setFuncType(0);
			getsubscriptionstatusCall.setData(getsubscriptionstatusBean);
			getsubscriptionstatusCall.callService();			
			Logger.verifyEquals("200", getsubscriptionstatusCall.getString("code"), "验证code");
			Logger.verifyEquals(true,getsubscriptionstatusCall.getJsonObject().get("data").isJsonNull(), "验证data为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//手动验证
	public void Tc_GetSubscriptionStatus_006() {
		Logger.start(true,"直播付费一年，是否可用，成功-type5");
		try {
			//这个数据从第三方同步过来无法自己制作所以用静态数据
			Integer mchId = 500950559;
			getsubscriptionstatusBean.setMchId(mchId);
			getsubscriptionstatusBean.setFuncType(5);
			getsubscriptionstatusCall.setData(getsubscriptionstatusBean);
			getsubscriptionstatusCall.callService();			
			Logger.verifyEquals("200", getsubscriptionstatusCall.getString("code"), "验证code");
			JsonObject data = getsubscriptionstatusCall.getJsonObject().getAsJsonObject("data");
//			Logger.verifyEquals(true, data.get("available").getAsBoolean(), "验证available");
//			Logger.verifyEquals(354, data.get("availableDay").getAsInt(), "验证availableDay");
//			Logger.verifyEquals(3, data.get("subscriptionStatus").getAsInt(), "验证subscriptionStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}